<?php
class Contact extends MY_Controller{

	function __construct()
	{
		parent::__construct();
		$this->load->library('googlemaps');
		$config = array('center'=>"50.835862,4.394384",'zoom'=>17,'map_height'=>'350','map_type'=>'ROADMAP');

		$marker = array();
		$marker['position'] = "50.835862,4.394684";
		$marker['title'] = "Massage Chinois Coquelicot";
		$marker['icon'] = base_url('resources/frontpage/imgs/gmapMaker.png');
		$marker['infowindow_content'] = "Le Super Grill | Brain l'Alleud";
		
		$this->googlemaps->initialize($config);
		$this->googlemaps->add_marker($marker);

		
	}

	public function index()
	{
		$data['map'] = $this->googlemaps->create_map();
		$data['title'] = $this->title('Contact');
		$this->load->view($this->theme.'/header',$data);
		$this->load->view($this->theme.'/contact');
		$this->load->view($this->theme.'/footer');
	}

	function sendEmail()
	{
		if($_POST)
		{
			$config['protocol'] = 'mail';
			$config['wordwrap'] = FALSE;
			$config['mailtype'] = 'html';
			$config['charset'] = 'utf-8';
			$config['crlf'] = "\r\n";
			$config['newline'] = "\r\n";
			$this->email->initialize($config);
			$this->email->from($_POST['email'], $_POST['email']);
			$this->email->to('info@massage-chinois-coquelicot.be');
			$this->email->subject('Reservation & Informations');

			$email = $this->load->view('default/email/email',$_POST,TRUE);
			$this->email->message($email);
			if($this->email->send()){
				redirect('contact/success');
			}else{
				redirect('contact/unsuccess');
			}
			
		}else{
			redirect('contact');
		}
	}
	
	function success()
	{
		$data['map'] = $this->googlemaps->create_map();
		$data['title'] = $this->title('contact');
		$this->load->view('default/header',$data);
		$this->load->view('default/email/sendSuccess');
		$this->load->view('default/footer');
	}
	
	function unsuccess()
	{
		$data['map'] = $this->googlemaps->create_map();
		$data['title'] = $this->title('contact');
		$this->load->view('default/header',$data);
		$this->load->view('default/email/unSuccess');
		$this->load->view('default/footer');
	}

}